#pragma once
#include "EngineObject.h"
#include "RenderSystem.h"

namespace DreamEngine 
{
	
class _EngineExport CTexture : public CEngineObject
{
public:
	CTexture(const CString& name);
	~CTexture(void);

	bool Create(CRenderSystem* pRenderSystem,D3DFORMAT textureFormat, \
		UINT width, UINT height,D3DPOOL pool=D3DPOOL_MANAGED,\
		DWORD usage=0, UINT mipLevel=0);

	bool CreateFromFile(CRenderSystem* pRenderSystem, const std::string& fileName, \
		D3DFORMAT textureFormat=D3DFMT_A8R8G8B8, UINT width=0, UINT height=0,\
		D3DPOOL pool=D3DPOOL_MANAGED, DWORD usage=0, int mipLevel=0);

	DWORD GetPixelColor(int x, int y);
	void  GetPixelColor(OUT D3DCOLORVALUE& color, int x, int y);
	void  SetPixelColor(int x, int y, DWORD color);
	void  SetPixelColor(int x, int y, const D3DCOLORVALUE& color);

	void  CopyFrom(CRenderSystem* pRenderSystem, CTexture* pSourceTexture);

	void SaveToFile(const std::string& fileName, D3DXIMAGE_FILEFORMAT fileFormat=D3DXIFF_DDS);
	

	const std::string& GetName(void)const		{ return m_name;}
	const std::string& GetFileName(void)const	{ return m_fileName;}

	IDirect3DTexture9* GetD3DTexture()const		{return m_pTexture;}


	void	GetLevelDesc(D3DSURFACE_DESC& d3dsd, int level=0);
	float	GetWidth(int level=0);
	float   GetHeight(int level=0);
	int		CaculatePixelByte(CTexture* pTexture);

	void	Release(void);
	
protected:

	CString				m_name;
};

}

